package com.example.springbootproject.service.impl;/*
 *@author 王志威
 *@datatime 2024/4/21 20:01
 *@editnote
 */

import com.example.springbootproject.mapper.TeacherMapper;
import com.example.springbootproject.pojo.Teacher;
import com.example.springbootproject.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;

    //    添加教师
    @Override
    public void addTeacher(Teacher teacher) {
        //先判断是否有该教师
        if (teacherMapper.findTeacherByName(teacher.getTeacherName())) {
            log.info("添加失败，该教师已存在");
        } else {
            teacherMapper.addTeacher(teacher);
        }
    }

    //    删除教师
    @Override
    public void deleteTeacher(Integer id) {
        //先判断是否有该教师
        if (teacherMapper.findTeacherById(id)) {
            teacherMapper.deleteTeacher(id);
        } else {
            log.info("删除失败，该教师不存在");
        }

    }

    //    修改教师
    @Override
    public void updateTeacher(Teacher teacher) {
        //先判断是否有该教师
        if (teacherMapper.findTeacherById(teacher.getId())) {
            teacherMapper.updateTeacher(teacher);
        } else {
            log.info("修改失败，该教师不存在");
        }

    }

    //    查询教师
    @Override
    public void findTeacher(Integer id) {
        //先判断是否有该教师
        if (teacherMapper.findTeacherById(id)) {
            teacherMapper.findTeacher(id);
        } else {
            log.info("查询失败，该教师不存在");
        }

    }
}
